package com.study.shiro.shirosimpledemo;
 
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
 
/**
 * 自定义数据源-通过MD5加密
 */
public class CustomRealmMD5 extends AuthorizingRealm{
 
    //用户认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {

        //authenticationToken为用户输入信息
        String userCode=(String)authenticationToken.getPrincipal();
        //模拟数据库操作查询用户
        if(!userCode.equals("zhw")){
            return null;
        }
        //查询密码为zhw123
        //密码zhw123 MD5盐zhw 加密后为
        String password="31479febd1ea96f16458ea7e101f5165";
 
        String salt="zhw";
 
        SimpleAuthenticationInfo info=new SimpleAuthenticationInfo(userCode,password, ByteSource.Util.bytes(salt),"customRealm");
 
        return info;
    }
    //用户授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }
 
 
}